package cn.edu.neusoft.maxingxin231.yuejian06.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Activity.PostDetailActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Activity.PostListActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.ClubBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.PostBean;

public class PostAdapter extends BaseAdapter<PostBean>{
    String id,posttitle;


    public PostAdapter(Context context, List<PostBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        PostBean postBean = items .get(position);
        if (postBean == null) return;
        PostViewHolder postViewHolder = (PostViewHolder)holder;
        postViewHolder.p_tv1.setText(postBean.getPost_title());
        postViewHolder.p_tv2.setText(postBean.getUser_name());
        postViewHolder.p_tv3.setText(postBean.getSee_number());
        id = postBean.getPost_id();
        posttitle = postBean.getPost_title();
        Picasso.with(context).load("http://10.0.2.2:80/yuejian14/public/static/picture/"+items.get(position).getPost_img()).into(postViewHolder.p_img1);

        postViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //条目点击事件
                Log.i("TEST", "onClick: ");
                Intent intent = new Intent(context,PostDetailActivity.class);
                intent.putExtra("post_id",items.get(position).getPost_id());
                intent.putExtra("user_name",items.get(position).getUser_name());
                intent.putExtra("post_title",items.get(position).getPost_title());
                intent.putExtra("post_time",items.get(position).getPost_time());
                intent.putExtra("post_img",items.get(position).getPost_img());
                intent.putExtra("user_pic",items.get(position).getUser_pic());
                context.startActivity(intent);

            }
        });
    }

    public void setList(List<PostBean> list){
        this.items = list;
        notifyDataSetChanged();
    }
}
